package com.frejoys.store.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.common.area.AdcodeCityDto;
import com.frejoys.common.dto.common.area.AdcodeProvinceDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.common.AreaItemVo;
import com.frejoys.dao.entity.Area;
import com.frejoys.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "省市区", description = "省市区")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixStore)
@Authorization(Authority.Private)
public class MallAreaController {

    private final AreaService areaService;

    @Operation(summary = "全部省")
    @PostMapping("/area/province")
    public Result<List<Area>> areaProvince() {
        return Result.success(areaService.getProvince());
    }

    @Operation(summary = "全部市")
    @PostMapping("/area/city")
    public Result<List<Area>> areaCity() {
        return Result.success(areaService.getCity());
    }

    @Operation(summary = "全部区县")
    @PostMapping("/area/district")
    public Result<List<Area>> areaDistrict() {
        return Result.success(areaService.getDistrict());
    }

    @Operation(summary = "指定省获取市")
    @PostMapping("/area/city/byProvince")
    public Result<List<Area>> areaCityByProvince(@RequestBody @Validated AdcodeProvinceDto dto) {
        return Result.success(areaService.getCity(dto.getAdcode()));
    }

    @Operation(summary = "指定市获取区县")
    @PostMapping("/area/district/byCity")
    public Result<List<Area>> areaDistrictByCity(@RequestBody @Validated AdcodeCityDto dto) {
        return Result.success(areaService.getDistrict(dto.getAdcode()));
    }

    @Operation(summary = "获取处理后的可用的省市区")
    @PostMapping("/area/dispose")
    public Result<List<AreaItemVo>> areaDispose() {
        return Result.success(areaService.getDisArea());
    }

}
